<?php

namespace app\common\model;

use think\Model;

/**
 * ServTeam
 */
class ServTeam extends Model
{
    // 表名
    protected $name = 'serv_team';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = true;

    // 追加属性
    protected $append = [
        'service',
    ];


    public function getServiceAttr($value, $row): array
    {
        return [
            'title' => \app\common\model\ServService::whereIn('id', $row['service_id'])->column('title'),
        ];
    }

    public function getServiceIdAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setServiceIdAttr($value): string
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function getImagesAttr($value): array
    {
        if ($value === '' || $value === null) return [];
        if (!is_array($value)) {
            return explode(',', $value);
        }
        return $value;
    }

    public function setImagesAttr($value): string
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    public function getContentAttr($value): string
    {
        return !$value ? '' : htmlspecialchars_decode($value);
    }

    public function member(): \think\model\relation\BelongsTo
    {
        return $this->belongsTo(\app\common\model\Member::class, 'member_id', 'id');
    }
}